In [6]:
#List Comprehension 형태
MAX = 1000
noprimes = [
j
for i in range(2, int(MAX ** 0.5) + 1)
for j in range(i*2, MAX, i)
]
primes = [
x for x in range(2, MAX) if x not in noprimes
]
print(primes)
In [7]:
primes = list(filter(lambda x: x not in noprimes, range(2, MAX)))
print(primes)
In [10]:
import functools
MAX = 1000
noprimes = list(map(
lambda i: list(map(
lambda j: j,
range(i*2, MAX, i))),
range(2, int(MAX**0.5) + 1)
))
noprimes = functools.reduce(
lambda x, y: x+y,
noprimes,
)
primes = list(filter(lambda x: x not in noprimes, range(2, MAX)))
print(primes)
In [12]:
"패스트캠퍼스".replace("패스트","Fast")
Out[12]:
In [13]:
"웹프로그래밍 스쿨과 데이터 사이언스 스쿨".replace("스쿨", "SCHOOL")
Out[13]:
In [1]:
def word_replace(sentence, find_word, replace_word):
result = ""
i = 0
while i < len(sentence):
is_exist = True
for j in range(len(find_word)):
if sentence[i+j] != find_word[j]:
is_exist = False
break
if is_exist:
result += replace_word
i += len(find_word)
else:
result += sentence[i]
i += 1
return result
In [2]:
word_replace("슬로슬로우캠퍼스슬로우","슬로우","slow")
Out[2]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
#3번 문제...? 모르겠습니다.
def change_weekday(num):
change_dic = {
"0": "월요일",
"1": "화요일",
"2": "수요일",
"3": "목요일",
"4": "금요일",
"5": "토요일",
"6": "일요일",
}
for key, value in change_dic.items():
num = num.replace(key, str(value))
return num
num = int(calendar.weekday(2016, 5, 8))
change_weekday("3")
#4번 문제...? 모르겠습니다.
histogram = input("문자열을 입력하세요: ")
word_count={}
for word in histogram.replace(',','').split():
if word in word_count:
word_count[word]+=1
else:
word_count[word]=1
print(word_count)
#5번 문제
how_much = int(input())
def fibonacci(how_much):
result = ""
for i in range(how_much):
result += how_much
return result